/*
 * Thread safe counter to record the total number of proxied connections to.
 *
 * Since all we have to return is a count, this just provides a synchronized
 *  method for getting and incrementing the value.
 *
 * @author Jonathan Walsh
 * @author Jesse Brown
 *
 */

package mitm;

public class StatsRecorder {
    private static StatsRecorder sr = null;  /*Singleton instance*/
    private int count;  /* The count */

    private StatsRecorder() {
	count = 0;
    }

    /*
     * Get the singleton instance
     */
    public static synchronized StatsRecorder getStatsRecorder() {
	if ( sr == null ) {
	    sr = new StatsRecorder();
	}
	return sr;
    }

    /* Add one to the count */
    public void incrementCount() {
	addToCount(1);
    }

    /* return the count */
    public int getCount() {
	return addToCount(0);
    }

    /* internal function for incrementing and getting the count */
    private synchronized int addToCount( int x ) {
	count += x;
	return count;
    }
}
